import React, { Component } from 'react'

import {getDatas} from '../../../utils/tools';
import {COURSE_TH} from '../../../config/table_config';

import CourseService from '../../../services/course';

import ListTitle from '../../../components/common/ListTitle';
import TableTh from '../../../components/common/TableTh'

import './index.scss'

const courseService = new CourseService();

export default class Course extends Component {
    constructor(props){
        super(props);
        this.state={
            title:'课程管理',
            thData:COURSE_TH,

        }
    }
    onRefreshData(){
       
    }
    async getCourseData(){
        const result = await courseService.getCourseData(),
              errorCode = result.error_code,
              data = result.data,
              {history} = this.props;
              
              getDatas(errorCode,data,history,()=>{
                const {courseData,fileData} = data;
                courseData.forEach((cItem,cIndex)=>{
                    if(cItem.field === 0){
                        cItem.fieldTitle = '无分类'
                    }
                    fileData.forEach((fItem,index)=>{
                        if(cItem.field === fItem.id){
                            cItem.fieldTitle = fItem.title
                        }
                    })
                })
                console.log(data);
                
              })
             
             
    }
    componentDidMount(){
        this.getCourseData()
    }
    render() {
        const {title,thData} = this.state;
        console.log(this.state);
        return (
            <div className="list-container">
               <ListTitle title={title}></ListTitle>
               <TableTh thData={thData} onRefreshData={this.getCourseData.bind(this)} ></TableTh>
            </div>
        )
    }
}
